Public Class RailFenceCipherForm

    Private objRFCipher As New RailFenceCipherEngine

    Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click
        If txtPlainText.Text.Trim = "" Or txtKey.Text.Trim = "" Then
            MessageBox.Show("Please fill value on plaintext and key box", "Incomplete Data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Else
            Try
                txtCipherText.Text = objRFCipher.Encrypt(txtPlainText.Text.Trim, txtKey.Text.Trim)
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub btnDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecrypt.Click
        If txtCipherText.Text.Trim = "" Or txtKey.Text.Trim = "" Then
            MessageBox.Show("Please fill data on ciphertext and key box", "Incomplete Data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Else
            Try
                txtPlainText.Text = objRFCipher.Decrypt(txtCipherText.Text.Trim, txtKey.Text.Trim)
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub
End Class
